<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text">
<input type="text">
<input type="button" value="加" onclick="fn(1)">
<input type="button" value="减" onclick="fn(2)">
<input type="button" value="乘" onclick="fn(3)">
<input type="button" value="除" onclick="fn(4)">
<h1>结果：<span></span></h1>
<script src="../jq.js"></script>
<script>
    function fn(flag) {
        let x = $("input:first").val()
        let y = $("input:eq(1)").val()
        if (isNaN(x)|| isNaN(y)){
            $("span").text(输入错误);
            return;
        }
        switch (flag) {
            case 1:
                $("span").text(x * 1 + y * 1);
                break;
            case 2:
                $("span").text(x * 1 - y * 1);
                break;
            case 3:
                $("span").text(x * 1 * y * 1);
                break;
            case 4:
                $("span").text(x * 1 / y * 1);
                break;
        }

    }

    function fn1() {
        let a = $("input:first").val()
        let b = $("input:eq(1)").val()
        let c = parseInt(a) + parseInt(b);
        $("span").text(c);
    }

    function fn2() {
        let a = $("input:first").val()
        let b = $("input:eq(1)").val()
        let c = parseInt(a) - parseInt(b);
        $("span").text(c);
    }

    function fn3() {
        let a = $("input:first").val()
        let b = $("input:eq(1)").val()
        let c = parseInt(a) * parseInt(b);
        $("span").text(c);
    }

    function fn4() {
        let a = $("input:first").val()
        let b = $("input:eq(1)").val()
        let c = parseInt(a) / parseInt(b);
        $("span").text(c);
    }



</script>
</body>
</html>